package com.example.checkbox

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.CheckBox
import android.widget.Toast

class MainActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        for (i in 1 ..3){
            val checkBox = findViewById<CheckBox>(R.id.checkbox + i)
            //获取复选框值
            checkBox.setOnClickListener(){
                if (it is CheckBox && it.isChecked){
                    Toast.makeText(this,"您选中了:" + it.text ,Toast.LENGTH_SHORT).show()
                }
            }


        }
    }
}
